package com.t.bricks.bussiness.controller.flowwork;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.t.bricks.bussiness.controller.common.BaseController;
import com.t.bricks.bussiness.db.entity.flowwork.FlowWorkNode;
import com.t.bricks.bussiness.service.flowwork.FlowWorkNodeService;
import com.t.bricks.model.MsgEmity;

/**
 * 流程实例节点控制层
 * 继承BaseController可直接实现通用方法,三个泛型代表:业务类、实体类、查询类
 * 通用业务类CommonService已经包含常用功能,使用自定义FlowWorkNodeService(需实现)可覆盖通用方法或扩展业务功能
 * 通用查询类可以直接使用Map,否则使用自定义ConditionFlowWorkNode(需实现)
 * @author HuangXinBian
 * @DateTime 2022年01月26日 15:18:58
 */
@RestController
@Api(value="流程实例节点", tags={"流程实例节点操作接口"})
@RequestMapping("/flow/work/node/")
public class FlowWorkNodeController extends BaseController<FlowWorkNodeService<FlowWorkNode>, FlowWorkNode, Map<String, Object>> {
	
	/**
	 * 控制操作,首位9不参与用6个数代表开关,0为不限制,1为限制
	 * 6个数的控制分别是:删除、修改、查询、导出、统计、步骤值可逆
	 * 其中前5个为'是否仅创建者可操作'后续为其它控制开关
	 */
	protected int enableTag = 9100000;

	/**
	 * 设置 检查待新增内容是否存在重复数据(多字段组合重复即重复)集合
	 * @return 返回的集合将覆盖父类的checkRepeatCombination成员,若返回null则不进行重复校验
	 */
	@Override
	protected List<String> setCheckRepeatCombination() {
		return Arrays.asList("sWorkId", "sName");//一个工作流实例中名称不能重复
	}

	/**
	 * 设置 检查待新增内容是否存在重复数据(单独字段重复即重复)集合
	 * @return 返回的集合将覆盖父类的checkRepeatAlone成员,若返回null则不进行重复校验
	 */
	@Override
	protected Map<String, Integer> setCheckRepeatAlone() {
		return null;
	}

	/**
	 * 修改指定节点内容描述
	 * @param uId
	 * @param iVersion
	 * @param sDescription
	 * @return
	 */
	@ApiOperation(value="修改指定节点内容描述")
	@ApiImplicitParams({
		@ApiImplicitParam(name="uId", value="节点编号", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="iVersion", value="版本号", dataType="Integer", paramType="query", required=true),
		@ApiImplicitParam(name="sDescription", value="节点内容描述", dataType="String", paramType="query", required=true)
	})
	@RequestMapping(method={RequestMethod.POST}, value="/edit/description")
	public MsgEmity editDescription(String uId, Integer iVersion, String sDescription) {
		return this.service().editDescription(uId, iVersion, sDescription);
	}

	/**
	 * 审批节点
	 * @param uId
	 * @param iVersion
	 * @param sAuditing 审批意见
	 * @param iSuccess 审批通过(布尔值,1:是)
	 * @return
	 */
	@ApiOperation(value="审批节点", response=FlowWorkNode.class)
	@ApiImplicitParams({
		@ApiImplicitParam(name="uId", value="节点编号", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="iVersion", value="版本号", dataType="Integer", paramType="query", required=true),
		@ApiImplicitParam(name="sAuditing", value="审批意见述", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="iSuccess", value="审批通过(布尔值,1:是)", dataType="Integer", paramType="query", required=true)
	})
	@RequestMapping(method={RequestMethod.POST}, value="/auditing")
	public MsgEmity auditing(String uId, Integer iVersion, String sAuditing, Integer iSuccess) {
		return this.service().auditing(uId, iVersion, sAuditing, iSuccess);
	}

	/**
	 * 查询实例下的所有节点
	 * @param sWorkId 所属实例编号
	 * @return MsgEmity 返回查询结果
	 */
	@ApiOperation(value="查询实例下的所有节点", response=FlowWorkNode.class)
	@ApiImplicitParams({
		@ApiImplicitParam(name="sWorkId", value="所属实例编号", dataType="String", paramType="query", required=true)
	})
	@RequestMapping(method={RequestMethod.POST}, value="/find/work")
	public MsgEmity findByWork(String sWorkId) {
		return this.service().findByWork(sWorkId);
	}

}
